package cn.sunzq.sqlite.demo.base.response;

import lombok.Data;
import lombok.experimental.Accessors;

import java.util.ArrayList;
import java.util.List;

@Data
@Accessors(chain = true)
public class ResponseDTO<T>{

	private static final long serialVersionUID = 3918877423924837166L;

	private int status = 200;
	private boolean redirect = true;
	private List<ResponseMessage> messages;
	private List<String> message = new ArrayList<>();
	private T body;
	private int errNum;
	public String errorMsg;
	private boolean success = true;
	/**
	 * 当前系统时间戳
	 */
	private Long timeStamp = System.currentTimeMillis();

	/**
	 * 响应使用
	 */
	public ResponseDTO(int status, String errorMsg, Object content, boolean success, Long timeStamp) {
		super();
		this.status = status;
		this.errorMsg = errorMsg;
		this.body = (T) content;
		this.timeStamp = timeStamp;
		this.success = success;
	}

	public ResponseDTO() {

	}
	public static ResponseDTO response401(){
		return new ResponseDTO().setStatus(BizHttpStatus.HTTP_STATUS_401.getStatus());
	}

	public static <T> ResponseDTO defaultResponse(T t){
		return new ResponseDTO().setStatus(BizHttpStatus.HTTP_STATUS_200.getStatus()).setBody(t);
	}

	public static ResponseDTO defaultErrorResponse(int httpStatus, List<ResponseMessage> singleMessage) {
		return new ResponseDTO().setStatus(httpStatus).setMessages(singleMessage);
	}

	public static  ResponseDTO defaultErrorResponse(List<ResponseMessage> singleMessage) {
		return new ResponseDTO().setStatus(BizHttpStatus.HTTP_STATUS_200.getStatus()).setMessages(singleMessage);
	}

	public static ResponseDTO defaultErrorResponse(BizHttpStatus bizHttpStatus, List<ResponseMessage> singleMessage) {
		return new ResponseDTO().setSuccess(false).setStatus(bizHttpStatus.getStatus()).setMessages(singleMessage);
	}


	public static ResponseDTO errorResponse(BizHttpStatus bizHttpStatus, List<ResponseMessage> singleMessage) {
		return new ResponseDTO().setStatus(bizHttpStatus.getStatus()).setMessages(singleMessage);
	}

}
